package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.BShoppingPlanChange;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.ExportBuyPlanService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: 采购管理 -> 采购计划导出
 * 查看 -> buy:buyexport:view
 * 驳回 -> buy:buyexport:edit
 * 导出 -> buy:buyexport:export
 * 变更删除 -> buy:buyexport:del
 *
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/exportBuyPlan")
public class ExportBuyPlanController extends BaseController {

    @Autowired
    private ExportBuyPlanService service;

    /**
     * 采购计划导出页面
     *
     * @return 路径
     */
    @GetMapping("/page")
    @RequiresPermissions({"buy:buyexport:view"})
    public String exportPage(Model model) {
        model.addAttribute("stocks", service.findStocks());
        return "buy/exportBuyPlan/page";
    }

    /**
     * 采购计划列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    public JsonResult list(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findBuyPlanByQuery(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 采购计划变更记录列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/change/list")
    @RequiresPermissions({"buy:buyexport:view"})
    public JsonResult changeList(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<BShoppingPlanChange> list = service.findBuyPlanChangeLogByQuery(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 导入批量撤销
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancel")
    @RequiresPermissions({"buy:buyexport:edit"})
    public JsonResult cancel(Integer id) {
        return jsonResult(service.cancel(id));
    } @ResponseBody
    /**
     * 导入单条撤销
     *
     * @param id 主键
     * @return json
     */
    @PostMapping("/cancelSingle")
    @RequiresPermissions({"buy:buyexport:edit"})
    public JsonResult cancelSingle(Integer id) {
        return jsonResult(service.cancelSingle(id));
    }

    /**
     * 删除变更记录
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/del")
    @RequiresPermissions({"buy:buyexport:del"})
    public JsonResult del(Integer id) {
        return jsonResult(service.delChangeBuyPlanById(id));
    }

    /**
     * 采购计划导出
     *
     * @param ids 主键集合
     * @return JsonResult
     */
    @ResponseBody
    @GetMapping("/export")
    @RequiresPermissions({"buy:buyexport:export"})
    public void export(String ids, String remark, HttpServletResponse response) {
        service.export(ids, remark, response);
    }
    /**
     * 采购计划导出附表
     *
     * @param ids 主键集合
     * @return JsonResult
     */
    @ResponseBody
    @GetMapping("/exportSchedule")
    @RequiresPermissions({"buy:buyexport:export"})
    public void exportSchedule(String ids, String remark, HttpServletResponse response) {
        service.exportSchedule(ids, remark, response);
    }

    /**
     * 采购计划变更记录导出
     *
     * @param ids 主键集合
     * @return JsonResult
     */
    @ResponseBody
    @GetMapping("/change/export")
    @RequiresPermissions({"buy:buyexport:export"})
    public void changeExport(String ids, String remark, HttpServletResponse response) {
        service.changeExport(ids, remark, response);
    }
    /**
     * 采购计划变更记录导出附表
     *
     * @param ids 主键集合
     * @return JsonResult
     */
    @ResponseBody
    @GetMapping("/change/exportSchedule")
    @RequiresPermissions({"buy:buyexport:export"})
    public void changeExportSchedule(String ids, HttpServletResponse response) {
        service.changeExportSchedule(ids, response);
    }

}
